package com.example.logistics.controller;

import com.example.logistics.controller.dto.CreateShipmentRequest;
import com.example.logistics.entity.Shipment;
import com.example.logistics.entity.ShipmentStatus;
import com.example.logistics.repository.ShipmentRepository;
import com.example.logistics.service.ShipmentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/shipments")
@RequiredArgsConstructor
public class ShipmentController {
    private final ShipmentService shipmentService;
    private final ShipmentRepository shipmentRepository;

    @GetMapping
    public List<Shipment> list() {
        return shipmentRepository.findAll();
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Shipment create(@Valid @RequestBody CreateShipmentRequest request) {
        return shipmentService.createShipment(request);
    }

    @PatchMapping("/{id}/status")
    public Shipment updateStatus(@PathVariable Long id, @RequestParam ShipmentStatus status) {
        return shipmentService.updateStatus(id, status);
    }
}


